package com.ouc.eddyAlgorithm.service.impl;


import com.ouc.common.core.text.Convert;
import com.ouc.eddyAlgorithm.domain.EddyGed;
import com.ouc.eddyAlgorithm.mapper.EddyGedMapper;
import com.ouc.eddyAlgorithm.service.IEddyGedService;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * gedyolo计算涡旋临时表Service业务层处理
 *
 * @author b504
 * @date 2023-02-25
 */
@Service
public class EddyGedServiceImpl implements IEddyGedService {
  @Autowired
  private EddyGedMapper eddyGedMapper;

  @Autowired
  SqlSessionFactory sqlSessionFactory;

  /**
   * 查询gedyolo计算涡旋临时表
   *
   * @param eddyId gedyolo计算涡旋临时表主键
   * @return gedyolo计算涡旋临时表
   */
  @Override
  public EddyGed selectEddyGedByEddyId(Integer eddyId) {
    return eddyGedMapper.selectEddyGedByEddyId(eddyId);
  }

  /**
   * 查询gedyolo计算涡旋临时表列表
   *
   * @param eddyGed gedyolo计算涡旋临时表
   * @return gedyolo计算涡旋临时表
   */
  @Override
  public List<EddyGed> selectEddyGedList(EddyGed eddyGed) {
    return eddyGedMapper.selectEddyGedList(eddyGed);
  }

  /**
   * 新增gedyolo计算涡旋临时表
   *
   * @param eddyGed gedyolo计算涡旋临时表
   * @return 结果
   */
  @Override
  public int insertEddyGed(EddyGed eddyGed) {
    return eddyGedMapper.insertEddyGed(eddyGed);
  }

  /**
   * 修改gedyolo计算涡旋临时表
   *
   * @param eddyGed gedyolo计算涡旋临时表
   * @return 结果
   */
  @Override
  public int updateEddyGed(EddyGed eddyGed) {
    return eddyGedMapper.updateEddyGed(eddyGed);
  }

  /**
   * 批量删除gedyolo计算涡旋临时表
   *
   * @param eddyIds 需要删除的gedyolo计算涡旋临时表主键
   * @return 结果
   */
  @Override
  public int deleteEddyGedByEddyIds(String eddyIds) {
    return eddyGedMapper.deleteEddyGedByEddyIds(Convert.toStrArray(eddyIds));
  }

  /**
   * 删除gedyolo计算涡旋临时表信息
   *
   * @param eddyId gedyolo计算涡旋临时表主键
   * @return 结果
   */
  @Override
  public int deleteEddyGedByEddyId(Integer eddyId) {
    return eddyGedMapper.deleteEddyGedByEddyId(eddyId);
  }

  @Override
  public void truncateTable() {
    eddyGedMapper.truncateTable();
  }

  @Override
  public void insertByBach(List<EddyGed> eddyGedList) {
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);

    EddyGedMapper mapper = sqlSession.getMapper(EddyGedMapper.class);
    for (EddyGed eddyGed : eddyGedList) {
      mapper.insertEddyGed(eddyGed);
    }

    sqlSession.commit();
    sqlSession.clearCache();
    sqlSession.close();
  }
}
